<?php
namespace SSO\Controller;

/***
 * 此控制器专门处理中云通单点登录数据处理
 */

class LoginController extends CommonController {

    /**
     * 认证 Token， 成功则返回 User id
     */
    public function verifyToken(){
        $get  = I('get.');
        $token = $get['token'];
        $callback = $get['callback'];
        $user = $this->getUserByToken($token);
        $result = null;
        if( ! is_null($user) ){
            $result    = $user->user_id;
        }
        echo $callback . '(' . $result . ')';
    }


    public function verifyTokenByPost(){
        $post  = I('post.');
        $token = $post['token'];
        $user = $this->getUserByToken($token);
        $result = null;
        if( ! is_null($user) ){
            $result    = $user->user_id;
        }
        $this->ajaxReturn($result);
    }

    /**
     * 清除 Token
     */
    public function clearToken(){
        $get  = I('get.');
        $token = $get['token'];
        $callback = $get['callback'];
        $result = $this->clearSSOToken($token);
        echo $callback . '(' . $result . ')';
    }
}
